import pymongo
from constants.mongodb_config import *

class Singleton(object):
    __instance = None
    def __new__(cls, *args, **kwargs):  # 这里不能使用__init__，因为__init__是在instance已经生成以后才去调用的
        if cls.__instance is None:
            cls.__instance = super(Singleton, cls).__new__(cls, *args, **kwargs)
        return cls.__instance

def set_mongodb_connect(clinet_name,sheet_tab_name):
    client = pymongo.MongoClient(IP, PORT)
    db_client = client.admin
    db_client.authenticate(USERNAME,PASSWORD)
    walden = client[clinet_name]
    sheet_tab = walden[sheet_tab_name]
    return sheet_tab

if __name__ == '__main__':
    sheet_tab = set_mongodb_connect('local','startup_log')
    for item in sheet_tab.find():
        print(item)



